package Servlet;

import MySql.MySqlTool;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by liushiyin on 17-11-17.
 */
public class PushBlog extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");

        String blogtitle=request.getParameter("blogtitle");
        String blogtext=request.getParameter("blogtext");
        String realtext=blogtext.replace(" ","");
        if(!blogtext.equals("")&&!blogtitle.equals("")){
            MySqlTool sqlTool=new MySqlTool();
            sqlTool.insert("insert into blog values('"+blogtitle+"','"+realtext+"')");
            sqlTool.close();
            request.setAttribute("status","islogin");
            request.getRequestDispatcher("EditBlog.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
